<template>
	<view class="home">
		<view class="head-display">
			<person-infrom class="login_header" :propName="userName" :propNum="userCode" propDepartment=""
				v-if="userName"></person-infrom>
				<view class="waiting-work">
					<view class="waiting-work-title">待审批:</view>
					<view :class="Cpu_allWaitNum!=0?'waiting-work-num':'waiting-work-num2'">{{Cpu_allWaitNum}}条</view>
				</view>
		</view>
		<template v-if="true">
			<!-- 普通包 -->
			<view class="layOut-nav-wrap">
				<view class="layOut-title">申请</view>
				<view class="layOut-wrap">
					<nav-card class="layOut-sub" title="请休假" bagColor="#FE9201" iconSrc="qingjia" @click='jumpLeave'>
					</nav-card>
					<nav-card class="layOut-sub" title="离职" bagColor="#FF632B" iconSrc="yuangonglizhi"
						@click='jumpQuitInforn'></nav-card>
					<nav-card class="layOut-sub" title="申请记录" bagColor="#0089FF" iconSrc="yiwancheng"
						@click='jumpLeaveInforn'></nav-card>
					<nav-card class="layOut-sub" title="销假" bagColor="#e14144" iconSrc="xiaohui" @click='jumpDestroyLeave'>
					</nav-card>
				</view>
			</view>
			<view class="layOut-nav-wrap">
				<view class="layOut-title">
					<text>信息</text>
				</view>
				<view class="layOut-wrap">
					<nav-card class="layOut-sub" v-for="(item,index) in salary" :title="item.title" :key="index"
						:bagColor="item.bagColor" :iconSrc="item.iconSrc" @click='jump(item.url)' :newtips='item.newtips'>
					</nav-card>
				</view>
			</view>
			<view class="layOut-nav-wrap">
				<view class="layOut-title">
					<text>审批</text>
				</view>
				<view class="layOut-wrap">
					<nav-card class="layOut-sub" v-for="(item,index) in examineNavList" :title="item.title" :key="index"
						:bagColor="item.bagColor" :iconSrc="item.iconSrc" @click='jump(item.url)' :newtips='item.newtips'>
					</nav-card>
				</view>
			</view>
		</template>
		<template v-if="false">
			<!-- 查看工资条的包 -->
			<!-- 需求取消 -->
			<view class="layOut-nav-wrap">
				<view class="layOut-title">工资</view>
				<view class="layOut-wrap">
					<nav-card class="layOut-sub" v-for="(item,index) in salary" :title="item.title" :key="index"
						:bagColor="item.bagColor" :iconSrc="item.iconSrc" @click='jump(item.url)' :newtips='item.newtips'>
					</nav-card>
				</view>
			</view>
		</template>
		
		<template v-if="true">
			<!-- 查看绩效的包 -->
			<view class="layOut-nav-wrap">
				<view class="layOut-title">
					<text>绩效</text>
				</view>
				<view class="layOut-wrap">
					<nav-card class="layOut-sub" v-for="(item,index) in merits" :title="item.title" :key="index"
						:bagColor="item.bagColor" :iconSrc="item.iconSrc" @click='jumpSpr(item.url)' :newtips='item.newtips'>
					</nav-card>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	import service from '../../common/service/new_file.js'
	import apiData from '../../common/utils/apiData.js'
	export default {
		data() {
			return {
				salary:[
					{
						title: "工资条",
						bagColor: "#4874c0",
						iconSrc: "gongzi",
						url: "../salary/salayrList/salayrList",
						newtips: 0,
						isVisit: true
					},
					{
						title: "个人信息",
						bagColor: "#0089FF",
						iconSrc: "gerenxinxi",
						url: "../me/me",
						newtips: 0,
						isVisit: true
					},
				],
				merits:[
					{
						title: "绩效审批",
						bagColor: "#e18e56",
						iconSrc: "shandiaorenyuan",
						url: "../merits/meritsExamine/meritsExamine",
						newtips: 0,
						isVisit: true
					},
					{
						title: "专项绩效",
						bagColor: "#45e122",
						iconSrc: "yuyueqingjia1",
						url: "../special/specialExamine/specialExamine",
						newtips: 0,
						isVisit: true
					},
				],//绩效
				examineNavList: [{
						title: "考勤审批",
						bagColor: "#00B852",
						iconSrc: "kaoqin1",
						url: "../attendance/remineThing",
						newtips: 0,
						isVisit: true
					},
					{
						title: "休假审批",
						bagColor: "#E1BF6B",
						iconSrc: "yuyueqingjia1",
						url: "../leave/leaveExamine/leaveExamine",
						newtips: 0,
						isVisit: true
					},
					{
						title: "离职审批",
						bagColor: "#E1BF6B",
						iconSrc: "shandiaorenyuan",
						url: "",
						newtips: 0,
						isVisit: false
					},
					{
						title: "工资审批",
						bagColor: "#0089FF",
						iconSrc: "gongzitiao-",
						url: "../salary/remineThing",
						newtips: 0,
						isVisit: true
					},
					{
						title: "销假审批",
						bagColor: "#e14144",
						iconSrc: "ziliaodanganwupinxiaohuishenpibiao",
						url: "../leave/destroyLeave/destroyExamine",
						newtips: 0,
						isVisit: true
					},
				],
				psnname: '',
				salaryRemineNum: '0',
				leaveRemineNum: '0',
				attendanceRemineNum: '0',
				examineNum: '0',
				quitRemineNum: '0',
				destroyNum: '0',
				userName: '',
				userCode: '',
				allWaitNum: '',
			}
		},
		onLoad() {
			this.userName = JSON.parse(uni.getStorageSync('user')).user_name;
			this.userCode = JSON.parse(uni.getStorageSync('user')).user_code;
			this.init();
		},
		onReady() {},
		onPullDownRefresh() {
			this.userName = JSON.parse(uni.getStorageSync('user')).user_name;
			this.userCode = JSON.parse(uni.getStorageSync('user')).user_code;
			this.init();
		},
		methods: {
			jumpDestroyLeave() {
				uni.navigateTo({
					url: "../leave/destroyLeave/destroyComit"
				})
			},
			jumpQuitInforn() {
				uni.showToast({
					icon: 'none',
					title: '暂未开放'
				})
				// uni.navigateTo({
				// 	url:'../quit/quit'
				// })
			},
			jumpLeaveInforn() {
				uni.navigateTo({
					url: '../applyRecord/applyRecord'
				})
			},
			jumpmy() {
				uni.showToast({
					icon: 'none',
					title: '暂未开放'
				})
				uni.navigateTo({
					url:'../me/me'
				})
			},
			jumpLeave() {
				uni.navigateTo({
					url: "../leave/leave/leave"
				})
			},
			jump(url) {
				if (url) {
					uni.navigateTo({
						url: url
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '暂未开放'
					})
				}
			},
			jumpSpr(url) {
				this.$store.commit("initExa")
				if (url) {
					uni.navigateTo({
						url: url
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '暂未开放'
					})
				}
			},
			init() {
				this.getAttendList()//考勤代办条数
				this.getLeaveList()//请假审批代办条数
				this.getSalaryList()//工资审批待办条数
				this.getQuitList()//离职审批代办条数
				this.getDestroyList()//销假审批待办条数
				this.getSpecialNum()//专项绩效审批待办条数
				this.getMeritsNum()//月绩效待办条数
			},
			getSalaryList() {
				let _this = this
				let date = {
					year: '',
					month: ''
				}
				let data = apiData.setSalaryList('6302', 'N', date, '2') //工资列表
				service.common(data, {
					success: function(res) {
						_this.examineNavList[3].newtips = res.data.VALUES.length
					}
				})
			},
			getAttendList() {
				let _this = this
				let initObj = {
					pk_team: '', //班组
					pk_period_b: '' //考勤期间
				}
				let data = apiData.setAtedanceList('HAAP', 'N', initObj)
				console.log(JSON.stringify(data))
				// let data = apiData.setAtedanceList('HAAP', 'N', initObj)
				service.common(data, {
					success: function(res) {
						_this.examineNavList[0].newtips = res.data.VALUES.length
					}
				})
			},
			getDestroyList() {
				let _this = this
				let initObj = {
					pk_team: '', //班组
					pk_period_b: '' //考勤期间
				}
				let data = apiData.setAtedanceList('HA02', 'N', initObj)
				service.common(data, {
					success: function(res) {
						_this.examineNavList[4].newtips = res.data.VALUES.length
					}
				})
			},
			getLeaveList() {
				let _this = this
				let head = {
					pk_leavetype: '',
					pk_period_b: '',
				}
				let data = apiData.setLeaveListData('HA01', 'N', head)
				service.common(data, {
					success: function(res) {
						_this.examineNavList[1].newtips = res.data.VALUES.length
					}
				})
			},
			getQuitList() {
				let _this = this
				let data = apiData.setQuitListData('6115', "N")
				service.common(data, {
					success: function(res) {
						_this.examineNavList[2].newtips = res.data.VALUES.length
					}
				})
			},
			getMeritsNum() {
				let _this = this;
				let head = {
					pk_leavetype: '',
					pk_period_b: ""
				};
				let data = apiData.setLeaveListData('WAMP', "N", head,"2");
				console.log(JSON.stringify(data))
				service.common(data, {
					success: function(res) {
						_this.merits[0].newtips = res.data.VALUES.length
					}
				});
			},
			getSpecialNum() {
				let _this = this;
				let head = {
					pk_leavetype: '',
					pk_period_b: ""
				};
				let data = apiData.setLeaveListData('WAEP', "N", head,"2");
				service.common(data, {
					success: function(res) {
						_this.merits[1].newtips = res.data.VALUES.length
					}
				});
			}
		},
		computed: {
			Cpu_distStatus(){
				return this.$store.state.power
			},
			Cpu_allWaitNum() {
				let allWaitNum = 0
				//审批里面的总待办数
				for (let i = 0; i < this.examineNavList.length; i++) {
					allWaitNum += this.examineNavList[i].newtips
				}
				//绩效里面的总待办数
				for (let i = 0; i < this.merits.length; i++) {
					allWaitNum += this.merits[i].newtips
				}
				return allWaitNum
			},
		},
	}
</script>

<style scoped lang="scss">
	.home {
		height: 100vh;
		background: #f3f3f3;
		padding: 0 36rpx;
		padding-bottom: 20rpx;
		.head-display {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 90rpx;
			padding-top: 20rpx;
			margin-bottom: 20rpx;

			.login_header {}
		}
	}
	.waiting-work {
		display: flex;
		font-size: 28rpx;
		align-items: center;
	
		.waiting-work-num {
			margin-left: 10rpx;
			color: red;
			font-size: 32rpx;
			font-weight: 600;
		}
	
		.waiting-work-num2 {
			margin-left: 10rpx;
			font-size: 28rpx;
		}
	}

	// .swiper-item-wrap {
	// 	margin: 0 auto;
	// 	width: 706rpx;
	// 	height: 296rpx;
	// 	border-radius: 18rpx;
	// 	overflow: hidden;
	// 	box-shadow: 6rpx 10rpx 15rpx rgba($color: #000000, $alpha:0.15);
	// }

	// .swiper {
	// 	height: 336rpx;
	// 	margin-bottom: 18rpx;
	// 	margin-top: 10rpx;
	// }

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	// .logo {
	// 	height: 200rpx;
	// 	width: 200rpx;
	// 	margin-top: 200rpx;
	// 	margin-left: auto;
	// 	margin-right: auto;
	// 	margin-bottom: 50rpx;
	// 	background: red;
	// }

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.layOut-nav-wrap {
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		margin-bottom: 30rpx;
		border-radius: 12rpx 12rpx 0 0;

		.layOut-title {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 26rpx;
			border-bottom: 2rpx solid #e6e6e6;
			font-size: 30rpx;
			font-weight: 600;
			color: #555555;
			border-radius: 12rpx 12rpx 0 0;
		}

		.layOut-wrap {
			display: flex;
			padding: 0 25rpx;
			flex-wrap: wrap;
			justify-content: flex-start;

			.layOut-sub {
				padding: 20rpx 0;
				width: 210rpx;
			}
		}
	}
</style>
